package lion.dev.constant;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;

/**
 *
 * @author lion
 * @date 2011-5-26
 *
 */
public class Const {

	public static class Database {

		public static int NORMAL = 1;
		public static int LOCKED = 2;
		public static int DELETED = 3;
	}

	// 不存在或无意义的int类型的常量
	public static final int NULL_UNDEFINED_INT_VALUE = -1;

	public static class Date {

		public static final String SYS_DATE_PATTERN = "yyyy-MM-dd";
		public static final String SYS_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";

		public static final String ORACLE_DATE_PATTERN = "yyyy-mm-dd";
		public static final String ORACLE_PAYBACK_DATE_PATTERN = "yyyy-mm";
		public static final String ORACLE_DATE_TIME_PATTERN = "yyyy-mm-dd hh24:mi:ss";

		public static final String LUCENE_DATE_PATTERN = "yyyyMMddHHmmss";
		public static final String YEAR_MONTH_PATTERN = "yyyy-MM";

		public static final long SECONDS_ONE_MINUTS = 60;
		public static final long SECONDS_ONE_HOUR = 3600;
		public static final long SECONDS_ONE_DAY = 86400;
	}

	public static class Attach {

		// 上传附件类型常量
		public static class FileType {

			public static final int FILE = 1;
			public static final int IMAGE = 2;
			public static final int VIDEO = 3;
			public static final int AUDIO = 4;

			private static Map<String, Integer> fileTypeMap = new HashMap<>();
			static {
				fileTypeMap.put("jpg,jpeg,bmp,gif,png,tiff,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw",
						FileType.IMAGE);
				fileTypeMap.put(
						"avi,mpg,mpeg,wmv,asf,rmb,swf,rmvb,mov,flv,dat,vob,mp4,3gp,mkv,rm,divx,m1v,m2v,mpc,pmv,gt,rmm,rt,smt,smil,dvs,vob",
						FileType.VIDEO);
				fileTypeMap.put("flac,ape,ogg,mpc,ac3,abs,au,cda,dac,m3u,mid,midi,mp1,mp2,mp3,mp4,ra,ram,vqf,wav",
						FileType.AUDIO);
			}

			public static final int getFileType(String fileName) {

				String ext = FilenameUtils.getExtension(fileName);

				for (String key : fileTypeMap.keySet()) {
					if (StringUtils.containsAny(key, ext)) { return fileTypeMap.get(key); }
				}
				return FileType.FILE;
			}
		}
	}
}
